
/**  
* @Title: SaplingTransactionManager.java  
* @Package org.sapling.data.utils  
* @Description: TODO
* @author DcfZero  
* @date 2021年6月3日  
* @version V1.0  
*/ 
package org.sapling.data.utils;

import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import lombok.Setter;

/**  
* TODO
* @ClassName: SaplingTransactionManager  
* @author DcfZero 
* @date 2021年6月3日  
*    
*/
public class SaplingTransactionManager {
	
	private DataSourceTransactionManager manager;
	private TransactionStatus status;
	
	private DefaultTransactionDefinition def = new DefaultTransactionDefinition();//事务定义类
   
	public SaplingTransactionManager(DataSourceTransactionManager manager) {
		this.manager = manager;
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
		this.status = manager.getTransaction(def);
	}
	
	public void commit() throws Exception{
		this.manager.commit(this.status);
	}
	
	public void rollback() throws Exception{
		this.manager.rollback(this.status);
	}
}
